package com.transaction.demo.base.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.transaction.demo.base.vo.req.SaveRoleMenuListReqVo;
import com.transaction.demo.base.vo.resp.RoleMenuRespVo;
import com.transaction.demo.common.util.Result;
import com.transaction.demo.common.util.ResultPage;
import com.transaction.demo.base.vo.req.SysRoleListReqVo;
import com.transaction.demo.base.vo.req.SysRoleAddReqVo;
import com.transaction.demo.base.vo.req.SysRoleUpdateReqVo;
import com.transaction.demo.base.vo.resp.SysRoleRespVo;
import com.transaction.demo.base.service.SysRoleService;

/**
 * 描述：角色表
 * 作者：马庆智
 * 日期：2023/03/28 17:07:14
 */
@Api(tags = "角色表")
@RestController
@RequestMapping("/sysRole")
public class SysRoleController {

	@Autowired
	private SysRoleService sysRoleService;

	/**
	 * 查询角色表列表
	 *
	 * @param record 请求参数
	 * @return SysRoleResp
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:14
	 */
	@ApiOperation("查询角色表列表")
	@PostMapping("/querySysRoleList")
	public Result<ResultPage<SysRoleRespVo>> querySysRoleList(@RequestBody @Valid SysRoleListReqVo record) {
		return Result.success(sysRoleService.querySysRoleList(record));
	}

	/**
	 * 查询角色菜单
	 *
	 * @param roleId 角色id
	 * @return SysUserResp
	 * @author 马庆智
	 * @date: 2023/3/30 9:26
	 */
	@ApiOperation("查询角色菜单")
	@GetMapping("/queryRoleMenuList")
	public Result<RoleMenuRespVo> queryRoleMenuList(@RequestParam(value = "roleId") Integer roleId) {
		return Result.success(sysRoleService.queryRoleMenuList(roleId));
	}

	/**
	 * 分配角色菜单
	 *
	 * @param record 请求参数
	 * @return SysUserResp
	 * @author 马庆智
	 * @date: 2023/3/30 9:18
	 */
	@ApiOperation("分配角色菜单")
	@PostMapping("/saveRoleMenuList")
	public Result<Integer> saveRoleMenuList(@RequestBody @Valid SaveRoleMenuListReqVo record) {
		return Result.success(sysRoleService.saveRoleMenuList(record));
	}

	/**
	 * 添加角色表
	 *
	 * @param record 请求参数
	 * @return Result<Integer>
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:14
	 */
	@ApiOperation("添加角色表")
	@PostMapping("/saveSysRole")
	public Result<Integer> saveSysRole(@RequestBody @Valid SysRoleAddReqVo record) {
		return Result.success(sysRoleService.saveSysRole(record));
	}

	/**
	 * 删除角色表
	 *
	 * @param ids 请求参数
	 * @return Result<Integer>
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:14
	 */
	@ApiOperation("删除角色表")
	@GetMapping("/deleteSysRole")
	public Result<Integer> deleteSysRole(String ids) {
		return Result.success(sysRoleService.deleteSysRole(ids));
	}

	/**
	 * 更新角色表
	 *
	 * @param record 请求参数
	 * @return Result<Integer>
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:14
	 */
	@ApiOperation("更新角色表")
	@PostMapping("/updateSysRole")
	public Result<Integer> updateSysRole(@RequestBody @Valid SysRoleUpdateReqVo record) {
		return Result.success(sysRoleService.updateSysRole(record));
	}

}